﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using TpExtensions;


namespace TpBaseObjects.Base
{
	public class ProjektLiquiRow
	{
		
		#region Members

		private Range myRow;
		
		#endregion

		#region Contructor

		public ProjektLiquiRow(Range row, bool ze)
		{
			myRow = row;
			if (ze)
			{
				CheckSummenFormel();
			}
		}

		#endregion

		#region Properties

		public DateTime Datum
		{
			get
			{
				DateTime ret = new DateTime(1900, 1, 1);
				Range r1 = myRow.Cells[1, "A"];
				if (r1.Value != null)
				{
					ret = Convert.ToDateTime(r1.Value);
				}
				return ret;
			}
			set
			{
				Range r1 = myRow.Cells[1, "A"];
				r1.Value = value;
			}
		}

		public string DebitorenKonto
		{
			get
			{
				string ret = "";
				Range r1 = myRow.Cells[1, "J"];
				if (r1.Value != null)
				{
					ret = Convert.ToString(r1.Value);
				}
				return ret;
			}
			set
			{
				Range r1 = myRow.Cells[1, "J"];
				r1.Value = value;
			}
		}

		public string DiktatZeichen
		{
			get
			{
				string ret = "";
				Range r1 = myRow.Cells[1, "T"];
				if (r1.Value != null)
				{
					ret = Convert.ToString(r1.Value);
				}
				return ret;
			}
			set
			{
				Range r1 = myRow.Cells[1, "T"];
				r1.Value = value;
			}
		}

		public string Firma
		{
			get
			{
				string ret = "";
				Range r1 = myRow.Cells[1, "B"];
				if (r1.Value != null)
				{
					ret = Convert.ToString(r1.Value);
				}
				return ret;
			}
			set
			{
				Range r1 = myRow.Cells[1, "B"];
				r1.Value = value;
			}
		}

		public string Kunde
		{
			get
			{
				string ret = "";
				Range r1 = myRow.Cells[1, "H"];
				if (r1.Value != null)
				{
					ret = Convert.ToString(r1.Value);
				}
				return ret;
			}
			set
			{
				Range r1 = myRow.Cells[1, "H"];
				r1.Value = value;
			}
		}

		public DateTime RechnungsDatum
		{
			get
			{
				DateTime ret = new DateTime(1900, 1, 1);
				Range r1 = myRow.Cells[1, "F"];
				if (r1.Value != null)
				{
					ret = Convert.ToDateTime(r1.Value);
				}
				return ret;
			}
			set
			{
				Range r1 = myRow.Cells[1, "F"];
				r1.Value = value;
			}
		}

		public string Rechnungsempfänger
		{
			get
			{
				string ret = "";
				Range r1 = myRow.Cells[1, "I"];
				if (r1.Value != null)
				{
					ret = Convert.ToString(r1.Value);
				}
				return ret;
			}
			set
			{
				Range r1 = myRow.Cells[1, "I"];
				r1.Value = value;
			}
		}

		public int RechnungsNummer
		{
			get
			{
				int ret = 0;
				Range r1 = myRow.Cells[1, "D"];
				if (r1.Value != null)
				{
					string t1 = Convert.ToString(r1.Value);
                    if(Extensions.isNumeric(t1, System.Globalization.NumberStyles.Any))
					{
						ret = Convert.ToInt32(r1.Value);
					}
				}
				return ret;
			}
			set
			{
				Range r1 = myRow.Cells[1, "D"];
				r1.Value = value;
			}
		}

		public double SummeBrutto
		{
			get
			{
				double ret = 0;
				Range r1 = myRow.Cells[1, "P"];
				if (r1.Value != null)
				{
                    if(Extensions.isNumeric(r1.Value, System.Globalization.NumberStyles.Any))
					{
						ret = Convert.ToDouble(r1.Value);
					}
				}
				return ret;
			}
			set
			{
				Range r1 = myRow.Cells[1, "P"];
				r1.Value = value;
			}
		}

		public string Type
		{
			get
			{
				string ret = "";
				Range r1 = myRow.Cells[1, "C"];
				if (r1.Value != null)
				{
					ret = Convert.ToString(r1.Value);
				}
				return ret;
			}
			set
			{
				Range r1 = myRow.Cells[1, "C"];
				r1.Value = value;
			}
		}

		#endregion

		#region Methods

		private void CheckSummenFormel()
		{
			Range r1 = myRow.Cells[1, "Q"];
            if (r1.Value != null) {
                return;
            }
            string t1 = Convert.ToString(r1.Value);
			if (String.IsNullOrEmpty(t1))
			{
				r1.Value = "=Q" + (r1.Row - 1).ToString() + "+P" + r1.Row.ToString();
				r1.Font.ThemeColor = XlThemeColor.xlThemeColorAccent2;
			}
		}

		#endregion

	}
}
